﻿namespace AbpPlusPlus
{
    using System;

    using Abp.Dependency;

    using Castle.MicroKernel.Registration;

    using MediatR;

    public static class IIocManagerMediatRExtensions
    {
        public static void RegisterMediator(this IIocManager iocManager,Type moduleType)
        {
            var container = iocManager.IocContainer;

            var assemblyDescriptor = Classes.FromAssemblyContaining(moduleType);

            container.Register(assemblyDescriptor.BasedOn(typeof(IRequestHandler<,>)).WithServiceAllInterfaces());
            container.Register(assemblyDescriptor.BasedOn(typeof(IAsyncRequestHandler<,>)).WithServiceAllInterfaces());
            container.Register(assemblyDescriptor.BasedOn(typeof(ICancellableAsyncRequestHandler<,>)).WithServiceAllInterfaces());
            container.Register(assemblyDescriptor.BasedOn(typeof(INotificationHandler<>)).WithServiceAllInterfaces());
            container.Register(assemblyDescriptor.BasedOn(typeof(IAsyncNotificationHandler<>)).WithServiceAllInterfaces());
            container.Register(assemblyDescriptor.BasedOn(typeof(ICancellableAsyncNotificationHandler<>)).WithServiceAllInterfaces());
            
        }
    }
}